package com.example.demo.MyStack.digui;

import com.alibaba.fastjson.JSON;
import com.example.demo.order.ArrayUtil;

public class guibin {
    public static void main(String[] args) {
        guibing();
    }

    public  static  void guibing(){
        ArrayUtil arrayUtil = new ArrayUtil();
        int[] array = arrayUtil.getArray(3);
        int[] array2 = arrayUtil.getArray(7);
        sort(array);
        sort(array2);
        System.out.println(JSON.toJSONString(array));
        System.out.println(JSON.toJSONString(array2));
        int[] array3 = new int[array.length + array2.length];
        meger(array, array2, array3, array.length, array2.length);
        System.out.println(JSON.toJSONString(array3));
    }

    //排序
    public static void sort(int[] array) {
        for (int i = 1; i < array.length; i++) {
            int k = i;
            int tem = array[i];
            while (k > 0 && tem < array[k - 1]) {
                array[k] = array[k - 1];
                k--;
            }
            if (k != i) {
                array[k] = tem;
            }
        }
    }

    public static void meger(int[] array1, int[] array2, int[] array3, int size1, int size2) {
        int index1 = 0;
        int index2 = 0;
        int index3 = 0;
        while (index1 < size1 && index2 < size2) {
            if (array1[index1] < array2[index2]) {
                array3[index3++] = array1[index1++];
            } else {
                array3[index3++] = array2[index2++];
            }
        }
        while (index1 < size1) {
            array3[index3++] = array1[index1++];
        }
        while (index2 < size2) {
            array3[index3++] = array2[index2++];
        }
    }
}
